package system.track;

/**
 * This class proveds special behavior for the parking block.
 * Specifically it overrides critical items and provides setters
 * for the blocks needed.
 *
 * @author David Kolb
 */
public class Block4 extends Block
{
    private boolean parking;
    private Switch cwParkingSwitch;
    private Switch ccwParkingSwitch;
    private Block cwParkingBlock;
    private Block ccwParkingBlock;

    public Block4()
    {
        super(4);
    }

    public void setParkingSwitch(Direction d, Switch s)
    {
        switch(d)
        {
            case CLOCKWISE:
                this.cwParkingSwitch = s;
                break;
            case COUNTERCLOCKWISE:
                this.ccwParkingSwitch = s;
                break;
            default:
                throw new IllegalArgumentException("Bad direction arg.");
        }
    }

    public void setParkingBlock(Direction d, Block b)
    {
        switch(d)
        {
            case CLOCKWISE:
                this.cwParkingBlock = b;
                break;
            case COUNTERCLOCKWISE:
                this.ccwParkingBlock = b;
                break;
            default:
                throw new IllegalArgumentException("Bad direction arg.");
        }
    }

    @Override
    public boolean isParkingBlock()
    {
        return true;
    }

    //TODO we may need to specify a direction here.
    @Override
    public synchronized void setPark(boolean flag)
    {
        if (flag)
        {
            this.ccwParkingSwitch.setAngle(SwitchAngle.NINETY_DEGREES);
            this.cwParkingSwitch.setAngle(SwitchAngle.NINETY_DEGREES);
        }
        else
        {
            this.ccwParkingSwitch.setAngle(SwitchAngle.ONE_EIGHTY_DEGREES);
            this.cwParkingSwitch.setAngle(SwitchAngle.ONE_EIGHTY_DEGREES);
        }
    }

    //TODO implement a getBlock algoritm that can return a parking block.
}
